<?php if ( ! defined("BASEPATH")) exit("No direct script access allowed");
class doc_languages extends MX_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->lang->load('doc_languages');
        $this->load->model("doc_languages_model");
    }
  
    public function sort($field = "created", $order = "desc")
    {
        $this->doc_languages_model->dataSort($field, $order);
        $this->index();
    }

    public function index($target = 0)
    {
        $arr = $this->doc_languages_model->dataIndex($target); 
        $breakCrum = '<a href="'.base_url().'">'.t("Home").'</a> » <span>'.t("doc_languages").'</span>';
        $data = array("content" => $this->load->view("doc_languages/main", $arr ,true), "breakCrum" => $breakCrum);
        $this->load->view("templates/admin", $data);
    } 
  
    public function find()
    {
        if (!isset($_POST["txt_find"])) return redirect(site_url("doc_languages/index"));
        if (isset($_POST["btnReset"]) && $_POST["btnReset"] == "Reset") 
            $this->session->unset_userdata("sm_find_doc_languages");
        else {
            $keyword = $this->input->post("txt_find", true);
            if ($keyword != "") {
                notify_set_messages(notify_info(t("Result")." ".$keyword), "doc_languages");
                $this->session->set_userdata("sm_find_doc_languages", $keyword);
            }
        }
    
        redirect(site_url("doc_languages/index"));
    }    
    public function add()
    {        
        $arr = $this->doc_languages_model->dataAdd();
        $breakCrum = '<a href="'.base_url().'">'.t("Home").'</a> » 
        <a href="/admin/doc_languages">'.t("doc_languages").'</a> » <span>'.t("Add").'</span>';
        $data = array("content" => $this->load->view("doc_languages/add", $arr, true), 
                      "breakCrum" => $breakCrum);
        $this->load->view("templates/admin", $data);
    }    
  
    public function edit($id)
    {       
        $arr = $this->doc_languages_model->dataEdit($id);
        $breakCrum = '<a href="'.base_url().'">'.t("Home").'</a> » 
        <a href="/admin/doc_languages">'.t("doc_languages").'</a> » <span>'.t("Edit").'</span>';
        $data = array("content" => $this->load->view("doc_languages/edit", $arr, true),
                "breakCrum" => $breakCrum);
        $this->load->view("templates/admin", $data);
    }
  
    public function doAdd()
    {
        if(!$this->doc_languages_model->checkForm()) {
            notify_set_messages(notify_error(validation_errors()), "doc_languages");
            return $this->add();
        }
        if ($this->doc_languages_model->doUpdate()) {
            notify_set_messages(notify_success(t("Record is added")), "doc_languages");
            return redirect(site_url("doc_languages"));    
        }
      
    }
  
    public function doEdit()
    {        
        if(!$this->doc_languages_model->checkForm()) {
            notify_set_messages(notify_error(validation_errors()), "doc_languages");
            return $this->edit(decrypt($_POST["idx"]));        
        }
        if ($this->doc_languages_model->doUpdate()) {
            notify_set_messages(notify_success(t("Record is updated")), "doc_languages");
            redirect(site_url("doc_languages"));   
        }
     
    } 
  
    public function del($id)
    {
        $result = $this->doc_languages_model->del($id);
        if (is_array($result) && $result[0] == -1) {
            notify_set_messages(notify_atten($result[1]), "doc_languages");
        } else {
            notify_set_messages(notify_success(t("Record is deleted")), "doc_languages");
        }
        redirect(site_url("doc_languages"));
    }     
        
}